package com.anti.modular.sys.app.controller;

import com.anti.commom.api.Result;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.jdbc.support.page.PageParam;
import com.anti.commom.annotation.BusinessLog;
import com.anti.modular.sys.app.param.SysAppParam;
import com.anti.modular.sys.app.service.SysAppService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description TODO
 * @Author anTi
 * @Date 2021-3-9
 */
@RestController
@RequestMapping("sysApp")
public class SysAppController {
    @Resource
    SysAppService sysAppService;

    /**
     * 添加系统应用
     */
    @PostMapping("add")
    @BusinessLog(title = "系统应用_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(SysAppParam.add.class) SysAppParam sysAppParam) {
        sysAppService.add(sysAppParam);
        return Result.success("新增成功！");
    }
    /**
     * 删除系统应用
     */

    @PostMapping("delete")
    @BusinessLog(title = "系统应用_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody SysAppParam sysAppParam) {
        sysAppService.delete(sysAppParam);
        return Result.success("删除成功！");
    }
    /**
     * 删除系统应用
     */
    @PostMapping("edit")
    @BusinessLog(title = "系统应用_修改", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody SysAppParam sysAppParam) {
        sysAppService.edit(sysAppParam);
        return Result.success("修改成功！");
    }


    /**
     * 设为默认应用
     */
    @PostMapping("setAsDefault")
    @BusinessLog(title = "系统应用_设为默认应用", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result setAsDefault(@RequestBody SysAppParam sysAppParam) {
        sysAppService.updateAsDefault(sysAppParam);
        return Result.success("设置成功！");
    }


    /**
     * 系统应用列表
     */
    @GetMapping("list")
    @BusinessLog(title = "系统应用_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result list(SysAppParam sysAppParam) {
        return Result.data(sysAppService.list(sysAppParam));
    }


    /**
     * 查询系统应用
     */
    @GetMapping("page")
    @BusinessLog(title = "系统应用_分页列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result page(PageParam pageParam,SysAppParam sysAppParam) {
        return Result.data(sysAppService.page(pageParam,sysAppParam));
    }
}
